﻿// -------------------------------------------------------------------------
//    @FileName         :    QiPaiNetPacketParse.h
//    @Author           :    Gao.Yi
//    @Date             :   2022-09-18
//    @Email			:    445267987@qq.com
//    @Module           :    NFNetPlugin
//
// -------------------------------------------------------------------------
#pragma once

#include <NFComm/NFPluginModule/NFIPacketParse.h>
#define MSG_HEAD_LEN 6

#pragma pack(2)
namespace proto_client2access
{
    class C2AMsgHead;
}

struct CSC2SPkgHead
{
	uint16_t m_wCmd;
	uint16_t m_wSeq;
	uint16_t m_wDataLen;
	char m_aData[];
};

struct CSS2CPkgHead
{
	int32_t m_iDataLen;
	uint16_t m_wCmd;
	uint16_t m_wSeq;
	uint16_t m_wReqSeq;
	char m_aData[];
};
#pragma pack()

enum
{
	CS_C2S_PKG_HEAD_SIZE = sizeof(CSC2SPkgHead),
	CS_S2C_PKG_HEAD_SIZE = sizeof(CSS2CPkgHead),
	MAX_CS_PKG_LEN = 65535,
};

class CustomPacketParse : public NFIPacketParse
{
public:
	CustomPacketParse();
	////////////////////////////////////////////////////////////////////
	virtual int DeCodeImpl(const char* strData, uint32_t unLen, char*& outData, uint32_t& outLen, uint32_t& allLen, NFDataPackage& recvPackage) override;
	virtual int EnCodeImpl(const NFDataPackage& recvPackage, const char* strData, uint32_t unLen, NFBuffer& buffer, uint64_t nSendBusLinkId = 0) override;

	// 使用 lzf 算法 压缩、解压
	virtual int CompressImpl(const char* inBuffer, int inLen, void* outBuffer, unsigned int outSize);
	virtual int DecompressImpl(const char* inBuffer, int inLen, void* outBuffer, int outSize);

	static bool IsPacketComplete(const char* szPackBuf, int iPackLen);
	static int  UnpackC2AHead(const char* szPackBuf, int iPackLen, proto_client2access::C2AMsgHead& oMsgHead, int& iHeadLen, int& iDataLen);;
};
